package test;


import com.xiaomi.cashpay.common.utils.cryptor.PaymentBase64Utils;
import com.xiaomi.cashpay.user.utils.UserSecurityUtils;
import com.xiaomi.keycenter.client.DataProtectionException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.*;

/**
 * Created on 2016/7/4.
 */
public class MiIds {
    public static void main(String[] args) throws Exception {
        test1();
    }

    static void test3() throws Exception {
        String decrypt = decrypt("BASE64_GCBL+Myn9IZwMLtDJLW1G+fkrmQx0k1TC8FSvc/ZHaKfdRgSJBaF6pYIQqa8eJl6V9tqVskBGBBLHRnAHbhG7afWDplXGUwbGBSktCkT3wiSKyrkUicjKweqi7bT3AA=");
        System.out.println("decrypt = " + decrypt);
    }

    public static String decrypt(String encryptText) throws UnsupportedEncodingException, DataProtectionException {
        if (encryptText == null) {
            return null;
        }

        if (encryptText.startsWith("BASE64_")) {
            byte[] cipher = PaymentBase64Utils.decode(encryptText);
            if ((cipher == null) || (cipher.length == 0)) {
                return "";
            }
            return UserSecurityUtils.decrypt(cipher);
        }

        return encryptText;
    }

    static void test2() throws Exception {
        int[] miids = new int[]{ 991417049, 993298726, 993335595, 994087040, 995356832, 9953697, 995812262, 99602301, 996116688, 997076393, 998153995, 998557257, 99905317};
        System.out.println(miids.length);
    }

    static void test1() throws Exception {
        String filePath = "D:/tmp/miids.txt";
        Scanner scanner = new Scanner(new File(filePath));

        ArrayList<String> miIds = new ArrayList<String>();

        while (scanner.hasNextLine()) {
            String miId = scanner.nextLine().trim();
            miIds.add(miId.trim());
        }
        Collections.sort(miIds);
        System.out.println("miIds = " + miIds);
    }
}
